Skip to content

CPP: Change some query severities#1192

Merged
jbj merged 2 commits intogithub:masterfrom
geoffw0:severity
Apr 5, 2019
Merged

CPP: Change some query severities#1192
jbj merged 2 commits intogithub:masterfrom
geoffw0:severity

Conversation

@geoffw0
Copy link
Copy Markdown
Contributor

@geoffw0 geoffw0 commented Apr 2, 2019

Looking through the LGTM results for Linux, I found some warnings that feel like they should be recommendations.

(I also think that some of the results for suspicious-pointer-scaling and dead-code-goto may be dubious, so I'm looking into that next)

@geoffw0 geoffw0 added the C++ label Apr 2, 2019
@geoffw0 geoffw0 requested a review from a team as a code owner April 2, 2019 11:26
Copy link
Copy Markdown
Contributor

@jbj jbj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with these changes. Both queries are good, but they're definitely recommendations.

I've thought sometimes about creating a query for Bug #6 in Curiously Recurring C++ Bugs at Facebook (an excellent talk, by the way), but that hasn't been necessary because the "Function declared in block" query has detected that bug. Now that we're downgrading this query, perhaps it's time to write a query for Bug #6 and give it high severity.

@geoffw0
Copy link
Copy Markdown
Contributor Author

geoffw0 commented Apr 2, 2019

Good idea, I'll look into it.

@geoffw0
Copy link
Copy Markdown
Contributor Author

geoffw0 commented Apr 3, 2019

I've thought sometimes about creating a query for Bug #6 in Curiously Recurring C++ Bugs at Facebook (an excellent talk, by the way), but that hasn't been necessary because the "Function declared in block" query has detected that bug.

I understood issue #6 to be a variable declaration, not a function declaration. Can you give me an example where "Function declared in block" catches something serious?

@geoffw0
Copy link
Copy Markdown
Contributor Author

geoffw0 commented Apr 3, 2019

I wrote some test cases and found the LocalVariableHidesGlobalVariable query is pretty effective at finding the problem as I understand it. The issue being, in practice this is often likely to be 'local variable hides class member variable' which I don't think we have a query for. Perhaps that should be the new query?

@jbj
Copy link
Copy Markdown
Contributor

jbj commented Apr 4, 2019

I'd misremembered Bug #6. I thought it was a variant of this bug, which I thought was easier to trigger.

I think a "local variable hides class member variable" query would be too noisy in practice. I wrote a less strict version of that for Java once to find methods that access a field without a qualifier when a local variable exists with the same name in that method. I think it has quite good results, but it's still very noisy: https://lgtm.com/query/1506250887340/. Anyway, that wouldn't detect Bug #6.

It would be great if we could write a generalised "expression has no effect" query for Bug #6 because I think that's the most general form of the problem. The default constructor probably sets some field to nullptr and does nothing else, and then the destructor has no effect when that field is nullptr. Such a query would unfortunately only work for types whose default constructor and destructor bodies are in the snapshot or are on a hard-coded list.

@geoffw0
Copy link
Copy Markdown
Contributor Author

geoffw0 commented Apr 4, 2019

I thought it was a variant of this bug, which I thought was easier to trigger.

I thought that might create a temporary mutex and lock it, but it seems to do nothing at all. Do you know why?

I'm thinking the way forward is to write some tests for these cases, see which existing queries help, and discuss further.

@geoffw0
Copy link
Copy Markdown
Contributor Author

geoffw0 commented Apr 4, 2019

but it seems to do nothing at all

... oh, because it's a function declaration. Hence the use of Function declared in block.

@jbj jbj merged commit d619a8c into github:master Apr 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants